package com.wq.jdk8;

import java.lang.ref.WeakReference;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @Author: wangqiang20995
 * @Date:2019/6/20
 * @Description:
 * @Resource:
 */
public class StaticInnerClass {


    static class LocalMap {

        static class Entry extends WeakReference<StaticInnerClass> {

            Object value;

            public Entry(StaticInnerClass referent, Object value) {
                super(referent);
                this.value = value;
            }
        }

        private Entry[] entries;

        private int size;

        public LocalMap() {
            this.entries = new Entry[4];
            this.size = 0;
        }

        public void set(StaticInnerClass inner, Object object) {
            Entry entry = new Entry(inner, object);
            int index = size & 3;
            this.entries[index] = entry;
            size++;
        }
    }

    private LocalMap localMap;

    public StaticInnerClass() {
        this.localMap = new LocalMap();
    }

    public void set(Object value) {
        this.localMap.set(this, value);
    }

    public static void main(String[] args) {
        StaticInnerClass s1 = new StaticInnerClass();
        s1.set("hello");
        StaticInnerClass s2 = new StaticInnerClass();
        s2.set("world");

//        ExecutorService service = new ThreadPoolExecutor(4, 6, 1000, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<>(3));
//        service.execute(() -> System.out.println("hello"));

        int capacity = (1 << Integer.SIZE - 3) - 1;
        System.out.println((2) & ~capacity);
        System.out.println("runState:" + Integer.toBinaryString((1 << 30) & ~capacity));
        System.out.println("2^30:" + ((1 << 30) & ~capacity));
        System.out.println("capacity:" + Integer.toBinaryString(~capacity));
        System.out.println(Integer.toBinaryString(-1 << 29));
        System.out.println(-1 << 2);

//        System.out.println(s1.localMap.entries);
//        System.out.println(s2.localMap.entries);

        System.out.println(14 & 5);
        System.out.println(14 % (6));
    }
}
